import { connect } from 'dva';
import DaylightPanel from './DaylightPanel';
import Measure3DPanel from './Measure3DPanel';
import BimTreePanel from './BimTreePanel';
import Slice3DPanel from './Slice3DPanel';
import LayerList from './LayerList';
import BaseMap from './BaseMap';
import cls from 'classnames';

import styles from './index.less';
import BimRender from './BimRender';
import { WORKING_TAB } from '@/models/app';

const RightContent = ({ dispatch, maptoolbar, isGlobalProcessRender, curWorkingTab }) => {
  const handleCloseClick = () => {
    console.log(maptoolbar.activeToolbar);
    dispatch({
      type: 'maptoolbar/updataActiveToolbar',
      payload: '',
    });
    if (maptoolbar.activeWidget != null) {
      if (!maptoolbar.activeWidget.destroyed) {
        maptoolbar.activeWidget.destroy();
        dispatch({
          type: 'maptoolbar/weijiandom',
          payload: null,
        });
        dispatch({
          type: 'maptoolbar/measureSwitchModel',
          payload: '',
        });
      }
    } else {
      dispatch({
        type: 'maptoolbar/measureSwitchModel',
        payload: 'line',
      });
    }
  };

  function renderContent() {
    switch (maptoolbar.activeToolbar) {
      case 'daylight': {
        return <DaylightPanel onClose={handleCloseClick} />;
      }
      case 'layerlist': {
        return <LayerList onClose={handleCloseClick} />;
      }

      case 'bimtree': {
        return <BimTreePanel onClose={handleCloseClick} />;
      }
      case 'measure': {
        return <Measure3DPanel onClose={handleCloseClick} />;
      }
      case 'slice': {
        return <Slice3DPanel onClose={handleCloseClick} />;
      }
      case 'drawcolor': {
        return <BimRender onClose={handleCloseClick} />;
      }
      case 'basemap': {
        return <BaseMap onClose={handleCloseClick} />;
      }
      default:
        break;
    }
    return null;
  }

  return (
    <div
      className={cls(styles.right, {
        [styles.rightGlobalRender]: curWorkingTab === WORKING_TAB[1],
        // [styles.rightGlobalRender]: isGlobalProcessRender ,
      })}
    >
      {renderContent()}
    </div>
  );
};

export default connect(({ maptoolbar, app }) => {
  return {
    maptoolbar,
    isGlobalProcessRender: app.isGlobalProcessRender,
    curWorkingTab: app.curWorkingTab,
  };
})(RightContent);
